package com.ant.collect.controller;


import com.ant.collect.common.ResultVo;
import com.ant.collect.dto.MaterialDto;
import com.ant.collect.handler.AntException;
import com.ant.collect.service.IMaterialService;
import com.ant.collect.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hzd
 * @since 2025-10-31
 */
@Api(tags = "披露表二产品接口")
@RestController
@RequestMapping("/material")
public class MaterialController {

    @Autowired
    IMaterialService materialService;

    @Autowired
    IUserService userService;

    /**
     * 分页查询用户数据
     *
     * @param
     * @return
     */
    @GetMapping("/list")
    public ResultVo queryPageList(MaterialDto dto) {
        Map<String, Object> map = materialService.queryPageList(dto);
        return ResultVo.success(map);
    }


    @ApiOperation(value = "保存行业信息")
    @PostMapping("/save")
    public ResultVo save(@RequestBody MaterialDto dto) {
        return ResultVo.success("添加成功", materialService.saveMaterial(dto));
    }

    @ApiOperation(value = "获取通过企业id获取列表")
    @ApiImplicitParam(name = "id", value = "企业id", required = true, dataType = "Integer", paramType = "query")
    @GetMapping("/listById")
    public ResultVo listById(Integer id) {
        if (id == null) {
            throw new AntException("请输入企业id");
        }
        return ResultVo.success("ok", materialService.listById(id));
    }

    @ApiOperation(value = "获取通过企业id获取审核通过列表")
    @ApiImplicitParam(name = "id", value = "企业id", required = true, dataType = "Integer", paramType = "query")
    @GetMapping("/listNewById")
    public ResultVo findListCompanyIdPage(MaterialDto dto) {
        Map<String, Object> map = materialService.findListCompanyIdPage(dto);
        return ResultVo.success(map);
    }

    @ApiOperation(value = "通过审核")
    @ApiImplicitParam(name = "id", value = "企业id", required = true, dataType = "Integer", paramType = "query")
    @GetMapping("/approved")
    public ResultVo approved(Integer id,Integer status) {
        materialService.findApproved(id,status);
        return ResultVo.success();
    }


    @ApiOperation(value = "获取通过id获取列表")
    @ApiImplicitParam(name = "id", value = "id", required = true,dataType = "Integer", paramType = "query")
    @GetMapping("/findMaterialDetails")
    public ResultVo findMaterialDetails(Integer id){
        if(id==null){
            throw new AntException("请输入id");
        }
        return ResultVo.success("ok",materialService.findMaterialDetails(id));
    }
}
